//@version: $Id: Map.h 64 2010-11-25 20:46:39Z NeurobaticsTim@gmail.com $

#pragma once

#include "Global.h"
#include "templatevector.h"

#ifdef _STANDALONE_MAP_H
#include "Windows.h"

struct Shape {
	int type;
	void setShapeType(int type) {this->type = type;}
	int getShapeTyp() {return type;}
	void rotate() {}
	int generate() {return rand();}
};
struct Location{
	int x, y;
};
struct UserInput {
	Location mouseGridLocation;
	Location mouseClick() {return mouseGridLocation;}
};

#else
#include "Shape.h"
#include "UserInput.h"
#endif

/*
Authors:
   Jared Bills
   Matthew Morril
   John Parks
*/
//The world map for bejeweled
class Map {
private:
	/*Author: Jared Bills*/
	//Grid of shapes as the map
	Shape m_vGrid[HEIGHT][WIDTH];
	/*Author: Jared Bills*/
	//Combo list
	TemplateVector<Combo> m_vMarkedCombos;
	/*Author: Jared Bills*/
	//Input buffer
	UserInput m_vClickBuffer[CLICK_MAX];
	//Current click to track for input
	unsigned int m_uiCurrentClick;

	
	/*Author: Jared Bills*/
	//Clears the combo list
	inline void clear();
	/*Author: Jared Bills*/
	//Swaps two shapes whith the specified coordinates, returns true if successful
	inline const bool swapQuick(const unsigned int & a_uiAx, const unsigned int & a_uiAy, const unsigned int & a_uiBx, const unsigned int & a_uiBy);
	/*Author: Jared Bills*/
	//Checks if there are three shapes close together horizontally or vertically anywhere on the grid and returns true if so
	//   Note: Also keeps track of the combos in the combo list (to be cleared with clear() later)
	inline const bool comboCheck();
	/*Author: Jared Bills*/
	//Checks if there are three shapes close together horizontally or vertically anywhere on the grid and returns true if so
	inline const bool comboCheckQuick();
	/*Author: Jared Bills*/
	//Uses the recorded two clicks to swap a given shape
	inline void handleClickInput();
public:
	//Constructor
	Map();
	//Destructor
	~Map();
	/*Author: John Parks*/
	//Initiates the map and returns true if successful
	//   Note: To be called following object instantiation
	const bool init();
	/*Author: Jared Bills*/
	//Swaps two shapes whith the specified coordinates and sets shapes to swap for display, returns true if successful
	const bool swap(const unsigned int & a_uiAx, const unsigned int & a_uiAy, const unsigned int & a_uiBx, const unsigned int & a_uiBy);
	/*Author: Jared Bills*/
	//Checks all possible swap combinations on the map and returns false if there are none left (game over)
	//   Note: Call comboRenew() prior to this
	const bool check();
	/*Author: Matthew Morril*/
	//Fills the map with new shapes to take the place of void combos
	void fill();
	/*Author: Jared Bills*/
	//Checks map for combos (without swapping), keeps track of them, and replaces those with new shapes, and returns true if combos were found and replaced
	//   Note: To be called prior to check()
	const bool comboRenew();
	/*Author: Matthew Morrill*/
	//Handles the input gotten from the UserInput class. It will track number of clicks, where, and decide when to swap.
	//   Note: Also should be able to handle keyboard presses
	void handleInput(UserInput a_vUI);

#ifdef _STANDALONE_MAP_H
	void draw();
#endif

};